'''
3
1 S 08:10
2 S 08:35
1 E 10:00
2 E 13:16
0 S 17:00
0 S 17:00

3 E 08:10
1 S 08:20
2 S 09:00
1 E 09:20
0 E 17:00
'''
status = dict()
n = int(input())
day = [[0, 0] for i in range(n)]


def nextday():
    global sum_time, sum_book
    sum_time = 0
    sum_book = 0


iday = 0
sum_time = 0
sum_book = 0

while True:
    s = input()
    if s == '':
        break
    book, opt, hm = s.split()
    hm = int(hm[:2]) * 60 + int(hm[3:])
    book, h, m = int(book),
    x = h * 60 + m
